/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.test;


import java.util.ArrayList;
import java.util.List;

import dex.compiler.model.base.Place;
import dex.compiler.model.program.Path;
import dex.compiler.problem.Ambiguity;
import dex.compiler.problem.Crime;
import dex.compiler.problem.Disagreement;
import dex.compiler.problem.Omission;
import dex.compiler.problem.Problem;
import dex.compiler.problem.Reporter;


/**
 * Stores reported problems in a list for later retrieval.
 */
public class StoreReporter implements Reporter {


	/**
	 * A problem and its detailed message.
	 */
	public static class Pair {


		/**
		 * The problem.
		 */
		public Problem problem;
		
		
		/**
		 * The problem's detailed message.
		 */
		public String message;
		
		
		/**
		 * Constructs a new pair.
		 * 
		 * @param problem  the problem
		 * @param message  its detailed message
		 */
		public Pair(Problem problem, String message) {
			this.problem = problem;
			this.message = message;
		}
	}


	/**
	 * The list of reported problems.
	 */
	final private List<Pair> reported;


	/**
	 * Constructs a new <code>StoreReporter</code>.
	 */
	public StoreReporter() {
		this.reported = new ArrayList<Pair>();
	}


	public void error(Ambiguity ambiguity, Place place, String name, List<Path> matches) {
		reported.add(new Pair(ambiguity, ambiguity.toMessage(place, name, matches)));
	}


	public void error(Crime problem, Place place, String offender) {
		reported.add(new Pair(problem, problem.getMessage(place, offender)));
	}


	public void error(Disagreement problem, Place place, String first, String second) {
		reported.add(new Pair(problem, problem.getMessage(place, first, second)));
	}


	public void error(Omission problem, Place place, String name) {
		reported.add(new Pair(problem, problem.getMessage(place, name)));
	}


	/**
	 * Returns the list of reported problems.
	 * 
	 * @return  the reported problems
	 */
	public List<Pair> getProblems() {
		return reported;
	}

}


